package bhbt.controller.member.info;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import bhbt.controller.core.BaseController;
import bhbt.model.Member;
import bhbt.model.Notice;
import bhbt.model.ParamWage;
import bhbt.service.MemberService;
import bhbt.service.NoticeService;
import bhbt.service.ParamWageService;
import bhbt.taglib.pagetag.Pagination;
import bhbt.utils.ContextUtil;






/**
 * Created by Administrator on 2016/3/25.
 */
@Controller
 
public class WelcomeInfoController extends BaseController {
    @Resource
    private NoticeService noticeService;
    @Resource
    private MemberService memberService;
    @Resource
    private ParamWageService paramWageService;
   
    @RequestMapping("member/info/welcome.shtml")
    public String add(ModelMap model,HttpServletRequest request, HttpServletResponse response) throws Exception{
    	
		 
    	//会员信息
    	Member member = ContextUtil.getMember();
    	member = memberService.getByKey(member.getId());
    	request.setAttribute("member",member);
    	
    	
    	//最新的公告列表
    	HashMap formMap = getParameterMap(request);
    	formMap.put("pagination.orderBy","commitDate desc");
        Pagination page = noticeService.queryForPageList("noticeForPage",formMap);
        request.setAttribute(Pagination.pageBeanName, page);
      
		 
		
        //优化后：（由请求6次数据库优化为只请求一次）
		ParamWage paramWage800=new ParamWage();
		ParamWage paramWage801=new ParamWage();
		ParamWage paramWage1003=new ParamWage();
		ParamWage paramWage1000=new ParamWage();
		ParamWage paramWage1002=new ParamWage();
		 
		Map paraMap = new HashMap();
		paraMap.put("where", "1=1 and id in (800,801,1003,1000,1002) ");
		List<ParamWage> paramWageList = this.paramWageService.queryForList("select", paraMap);
		for (ParamWage paramWage : paramWageList) {
			if(800 == paramWage.getId()){
				 
				paramWage800 = paramWage;
				continue;
			}
			else if(801 == paramWage.getId()){
				 
				paramWage801 = paramWage;
				continue;
			}
			else if(1003 == paramWage.getId()){
				 
				paramWage1003 = paramWage;
				continue;
			}
			else if(1000 == paramWage.getId()){
				 
				paramWage1000 = paramWage;
				continue;
			}
			else if(1002 == paramWage.getId()){
				 
				paramWage1002 = paramWage;
				continue;
			}
			
		}
        
        
		//今日推出矿点数
		
		 
		double paramWageDouble800 =paramWage800.getValue();
		Integer paramWageInt800 = (int)paramWageDouble800;
		
		request.setAttribute("paramWage800",paramWageInt800);
		//今日可买矿点数
	 
		double paramWageDouble801 =paramWage801.getValue();
		Integer paramWageInt801 = (int)paramWageDouble801;
		
		
		request.setAttribute("paramWage801",paramWageInt801);
		
		
		//矿点价格
		 
		request.setAttribute("paramWage1003",paramWage1003.getValue());
		 
		
		 
		request.setAttribute("paramWage1000",paramWage1000.getValue());
		 
		 
		request.setAttribute("paramWage1002",paramWage1002.getValue());
		 
		
		
		
		
		return "member/info/welcome";
        
		
     
    }
     
}
